package com.google.code.server4j.handler;

import java.io.IOException;

import com.google.code.server4j.connector.Request;
import com.google.code.server4j.connector.Response;
import com.google.code.server4j.util.BaseLifeCycle;
import com.google.code.server4j.util.Log;

public class ServerHandler extends BaseLifeCycle implements Handler {

	private String webContext;
	private String notfountPage;
	
	public void setNotfountPage(String notfountPage) {
		this.notfountPage = notfountPage;
	}

	public void setWebContext(String webContext) {
		this.webContext = webContext;
	}


	@Override
	public void handle(Request req, Response resp) throws IOException {
		
		String context = req.getContext();
		Log.debug("handle context is "+context);
		resp.setContext(context);
		resp.setWebRoot(webContext);
		try {
			resp.response();
		} catch(IOException e) {
			Log.warn("404");
			resp.response404(notfountPage);
		}
		
	}

}
